﻿/*
    Copyright 2010, 2011 Eric Wong
	contact@optimalcycling.com
	http://www.optimalcycling.com
	Optimal Cycling - Advanced power pacing program for cyclists
	
	This file is part of Optimal Cycling.

    Optimal Cycling is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Optimal Cycling is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Optimal Cycling.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _FILE_INTEGRATOR_H_
#define _FILE_INTEGRATOR_H_

#ifndef __OPENCL_VERSION__
	#include "Options.h"
	#include "Constants.h"
	#include "Vector.h"
	#include "Model.h"
#endif

#define INTEGRATOR_VARS_TO_MODEL iPower, powerVal, coursePosPoints, coursePosLinear, coursePosLinearMax, \
	coursePosDirection, coursePosInfo, riderProp, wind, climate, \
	numSimPoints, dragCoeffWheelYawAngles, dragCoeffWheels, dragCoeffWheelsNumPts, modelInfo

/// <summary>
/// One step of the integration procedure
/// </summary>
/// <param name="iParams">Pointer to a struct of params used for persistent storage in the integration steps</param>
/// <param name="t1"> The time at the end of the time interval</param>
/// <param name="y1"> The vector of next positions</param>
/// <param name="dy1"> The vector of next velocities</param>
/// <param name="d2y1"> The vector of next accelerations</param>
/// <returns></returns>
int RKF45Step(
		real4* iData,	 // real* t1 {s0}, real* y1 {s1}, real* dy1 {s2}, real* d2y1 {s3},
		real4* iCorrectionData,
		real4* iParams1,	// real t0 {s0}, y0 {s1}, dy0 {s2}, d2y0 {s3}
		real2* iParams2,	// H {s0}, lastDecreasedH {s1}
		__global const real4* iConstants,	// real Tol {s0}, Hmin {s1}, Hmax {s2}, Hstart {s3};
		real* iPower,
		__global const real* powerVal,
		__global const real4* coursePosPoints, 
		__global const real* coursePosLinear,
		const real coursePosLinearMax,
		__global const real4* coursePosDirection,
		__global const real4* coursePosInfo, 
		__global const real4* riderProp,
		__global const real4* wind, 
		__global const real4* climate,
		const sizeT numSimPoints,

		__global const real* dragCoeffWheelYawAngles,
		__global const real2* dragCoeffWheels, 
		const sizeT dragCoeffWheelsNumPts,

		__global const ModelInfo* modelInfo);

#endif		// _FILE_INTEGRATOR_H_

